package com.example.cloud.service.basic.config.impl;

import com.example.cloud.dao.basic.config.SeasonRemindRepository;
import com.example.cloud.model.config.SeasonRemind;
import com.example.cloud.model.system.User;
import com.example.cloud.service.basic.config.SeasonRemindService;
import com.example.cloud.utils.BusinessUtil;
import com.example.cloud.utils.RequestUtil;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import java.util.List;

/**
 * Created by wangtao on 2018/6/12.
 */
@Service
public class SeasonRemindServiceImpl implements SeasonRemindService {

    private static final Logger logger = Logger.getLogger(SeasonRemindServiceImpl.class);

    @PersistenceContext
    EntityManager em;

    @Autowired
    private SeasonRemindRepository seasonRemindRepository;

    @Override
    public SeasonRemind findOne(Long id) {
        return seasonRemindRepository.findOne(id);
    }

    @Override
    public List<SeasonRemind> findAll() {
        return null;
    }

    @Override
    @Transactional
    public void doSave(SeasonRemind record) {
        if(record.getId() == null){
            User user = RequestUtil.getLoginUser();
            record.setAccountId(user.getAccountId());
        }
        BusinessUtil.appendRecord(record);
        seasonRemindRepository.save(record);
    }

    @Override
    @Transactional
    public void doDelete(List<Long> ids) {
        seasonRemindRepository.deleteByIdIn(ids);
    }
}
